﻿#define _CRT_SECURE_NO_WARNINGS 1

//703. 数据流中的第 K 大元素
class KthLargest {
public:

    priority_queue<int, vector<int>, greater<int>> heap;
    int _k;

    KthLargest(int k, vector<int>& nums) {
        _k = k;
        for (auto& x : nums)
        {
            heap.push(x);
            if (heap.size() > k) heap.pop();
        }

    }

    int add(int val) {
        heap.push(val);
        if (heap.size() > _k) heap.pop();
        return heap.top();

    }
};
